package me.zhengjie.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;





@Component
public class MessageUtil {
    /**
     * ali:
     *   message:
     *     access-key-id: LTAI4G9RottBXuiv9qtKhXy5
     *     access-key-secret: TW6It8D2QemJu4b9VQzehuiykrEYGi
     */



    private static String accessKeyId = "LTAI4G9RottBXuiv9qtKhXy5";

    private static  String accessKeySecret = "TW6It8D2QemJu4b9VQzehuiykrEYGi" ;





    /**
     *
     * 给指定手机号发送指定模板消息
     *
     * @param phone
     * @param aliMessageEnum
     * @return
     */
    public static CommonResponse sendSimpleMessage(String phone, AliMessageEnum aliMessageEnum , String params) throws ClientException {
        // 创建DefaultAcsClient实例并初始化
        DefaultProfile profile = DefaultProfile.getProfile(
                "cn-hangzhou",          // 地域ID
                accessKeyId,      // RAM账号的AccessKey ID
                accessKeySecret); // RAM账号AccessKey Secret

        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        // 参数
        request.putQueryParameter("PhoneNumbers", phone );
        request.putQueryParameter("SignName", aliMessageEnum.getSignName());
        request.putQueryParameter("TemplateCode", aliMessageEnum.getTemplateCode());
        request.putQueryParameter("TemplateParam", params);

        return client.getCommonResponse(request);



    }


}
